#!/usr/bin/perl
#target_mod.cgi
require './tgtman-lib.pl';

&ReadParse();

$tname = $in{'targetid'};
@tlist=&get_target_list();
$found = 0;
my $tg;
foreach $t (@tlist) {
	if($t->{'fullname'} eq $tname) {
		$found = 1;
		$tg = $t;
	}
}
if(!$found){
	$err_msg = "No target selected!";
	goto ERROR_OUT;	
}

$err_msg = &del_target($tg, @tlist);
#goto ERROR_OUT;
$rc = `/etc/init.d/iscsi-target status`;
if($rc =~ /running/){
        `/etc/init.d/iscsi-target restart`;
}
&redirect("index.cgi");
ERROR_OUT:
&error_setup("");
&error($err_msg);
